<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script type="module">


    // 同时启动多个异步操作  => 按顺序返回结果
    var p1 = getNumAsync(1, 2000);
    var p2 = getNumAsync(2, 1000);
    var p3 = getNumAsync(3, 3000);


    var a = await p1; // {<pending>:undefined}  2s后   {<fulfilled>:1}
    console.log(a);

    var b = await p2; // {<pending>:undefined}  2s后   {<fulfilled>:1}
    console.log(b);

    var c = await p3; // {<pending>:undefined}  2s后   {<fulfilled>:1}
    console.log(c);


    console.log(4);





    function getNumAsync(num, delay = 0, isFulfilled = true) {
        var p = new Promise(function (resolve, reject) {
            setTimeout(function () {
                isFulfilled ? resolve(num) : reject(num);
            }, delay);
        });
        return p;
    }

</script>

</html>